package com.itqf.serializer;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/21
 * @Time: 上午10:59
 */
public class MySerializer implements ObjectSerializer {
    @Override
    public void write(JSONSerializer jsonSerializer, Object o, Object o1, Type type, int i) throws IOException {
        Double d = (Double)o;
        //四舍五入
        String r = "￥"+BigDecimal.valueOf(d).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"元";

        //把处理后的结果响应回去
        jsonSerializer.write(r);

    }
}
